from sqlalchemy import create_engine, text, Column, Integer, String, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


Base = declarative_base()

class Product(Base):
    __tablename__ = 't_user'

    id = Column(Integer, Sequence('id'), primary_key=True)
    name = Column(String)
    gender = Column(String)
    age = Column(Integer)

    def __repr__(self):
        return "Product(id=%d, name=%s, gender=%s, age=%d)"(self.id, self.name, self.gender, self.age)


# DB_CON_STR = 'mysql+mysqldb://root:ut123456@localhost/testdatabase?charset=utf8'
DB_CON_STR = 'mysql+pymysql://root:ut123456@localhost/testdatabase?charset=utf8'
engine = create_engine(DB_CON_STR, echo=False)

Session = sessionmaker(bind = engine)
session = Session()


res = session.query(Product).filter(text("id=1")).one()
print(res.id, res.name, res.gender)